#include "mangalist.h"

MangaList::MangaList()
{
}
MangaList::~MangaList()
{
    while(!this->isEmpty())
    {
	Manga* m = (Manga*)this->takeFirst();
	delete m;
    }
}
void MangaList::clearList()
{
     while(!this->isEmpty())
    {
	Manga* m = (Manga*)this->takeFirst();
	delete m;
    }
}
bool MangaList::serialize(QXmlStreamWriter * w)
{
    int count = this->count();
    w->setAutoFormatting(true);
    w->writeStartDocument();
    w->writeStartElement("MangaList");
    for(int i=0;i<count;i++)
    {
	Manga* m = (Manga*)this->at(i);
	m->serialize(w);
    }
    w->writeEndElement();
    w->writeEndDocument();
    return true;
}
bool MangaList::deserialize(QXmlStreamReader * r)
{
    while(!r->atEnd())
    {
	if(r->isStartElement() && r->name().toString() == "Manga")
	{
	    Manga * m = new Manga();
	    m->deserialize(r);
	    this->append(m);
	}
	r->readNext();
    }
    return true;
}
